package io.renren.modules.generator.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.renren.common.utils.Query;
import io.renren.common.utils.ResultUtil;
import io.renren.modules.generator.entity.TTrainingDictionaryEntity;
import io.renren.modules.user.entity.TPeopleEntity;
import io.renren.modules.user.entity.form.PeopleForm;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.generator.entity.TObjectEntity;
import io.renren.modules.generator.service.TObjectService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 考核课目
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-08-02 10:30:00
 */
@RestController
@RequestMapping("/tobject")
public class TObjectController {
    @Autowired
    private TObjectService tObjectService;

    /**
     * 列表 系统自带单表
     */
    @RequestMapping("/list")
    @ResponseBody
    //@RequiresPermissions("generator:tobject:list")
    public R list(@RequestBody TObjectEntity params){
        Map<String,Object> a=new HashMap<>();
        a.put("page",params.getPage().toString());
        a.put("limit",params.getLimit().toString());
        PageUtils page = tObjectService.queryPage(a);

        return R.ok().put("page", page);
    }


    /**
     * 列表
     */
    @RequestMapping("/selectList")
    @ResponseBody
    @RequiresPermissions("generator:tobject:list")
    public R selectList(@RequestBody TObjectEntity tObjectEntity){
        Map<String,Object> params=new HashMap<String,Object> ();
        params.put("page",tObjectEntity.getPage());
        params.put("limit",tObjectEntity.getLimit());
        params.put("name",tObjectEntity.getName());
        params.put("team",tObjectEntity.getTeam());
        PageUtils page = tObjectService.selectList(params);
        return R.ok().put("page", page);
    }


    /**
     * 列表
     */
    @RequestMapping("/selectObjectList")
    @ResponseBody
    public R selectObjectList(@RequestBody TObjectEntity tObjectEntity){
        Map<String,Object> params=new HashMap<String,Object> ();
        params.put("page",tObjectEntity.getPage());
        params.put("limit",tObjectEntity.getLimit());
        params.put("name",tObjectEntity.getName());
        params.put("team",tObjectEntity.getTeam());
        PageUtils page = tObjectService.selectList(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info")
    //@RequiresPermissions("generator:tobject:info")
    public R info(@RequestBody TObjectEntity objectEntity){
		TObjectEntity tObject = tObjectService.getById(objectEntity.getId());
        List<TTrainingDictionaryEntity> list=tObjectService.getObject();   //科目分类下拉框
        return R.ok().put("tObject", tObject).put("list",list);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("generator:tobject:save")
    public R save(@RequestBody TObjectEntity tObject){
		tObjectService.save(tObject);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("generator:tobject:update")
    public R update(@RequestBody TObjectEntity tObject){
		tObjectService.updateById(tObject);

        return R.ok();
    }

    /**
     * 删除  直接删的
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("generator:tobject:delete")
    public R delete(@RequestBody Integer[] ids){
		tObjectService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
    /**
     * 逻辑删除的
     */
    @RequestMapping("/del")
    @ResponseBody
    //@RequiresPermissions("generator:tobject:delete")
    public R del(@RequestBody TObjectEntity id){
        tObjectService.delTObjectEntity(id.getId());
        return R.ok();
    }
    /**
     * 下拉框
     */
    @RequestMapping("/getObject")
    public R getObject(){
        List<TTrainingDictionaryEntity> list=tObjectService.getObject();
        List<TTrainingDictionaryEntity> team=tObjectService.getTeam();
        return R.ok().put("list",list).put("team",team);
    }

}
